package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.data.Result;
import com.dk.data.ResultEnum;
import com.dk.pojo.seller.TbSeller;
import com.dk.service.seller.SellerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@CrossOrigin
@RequestMapping("seller")
@Controller
public class SellerController {

    private final Logger logger = LoggerFactory.getLogger(SellerController.class);
    @Reference
    private SellerService sellerService;

    @RequestMapping("listSeller")
    @ResponseBody
    public Result listSeller() {
        try {
            List<TbSeller> list = sellerService.listSeller();
            return Result.response(ResultEnum.OK).setData(list);
        } catch (Exception e) {
            logger.error("查询seller列表错误",e);
            return Result.response(ResultEnum.FAIL);
        }
    }

    @RequestMapping("sellerBySellerId/{sellerId}")
    @ResponseBody
    public Result sellerBrSellerId(@PathVariable("sellerId") String sellerId) {
        try {
            TbSeller seller = sellerService.SellerBySellerId(sellerId);
            return Result.response(ResultEnum.OK).setData(seller);
        } catch (Exception e) {
            logger.error("通过id获取商家错误");
            return Result.response(ResultEnum.FAIL);
        }
    }

    @RequestMapping("examine")
    @ResponseBody
    public Result examine(String staus,String sellerId) {
        try {
            System.out.println(staus);
            int i = sellerService.examineSeller(staus,sellerId);
            return Result.response(ResultEnum.OK);
        } catch (Exception e) {
            logger.error("商户审核错误",e);
            return Result.response(ResultEnum.FAIL);
        }
    }
}
